package csc.daonjpa.java.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import share.Constant;
import csc.daonjpa.java.dao.TransactionStateDAO;
import csc.daonjpa.java.domain.TransactionState;

@Service
public class TransactionStateService {
	
	@Autowired
	TransactionStateDAO transactionStateDAO;
	
	/**
	 * @return the transactionStateDAO
	 */
	public TransactionStateDAO getTransactionStateDAO() {
		return transactionStateDAO;
	}

	/**
	 * @param transactionStateDAO the transactionStateDAO to set
	 */
	public void setTransactionStateDAO(TransactionStateDAO transactionStateDAO) {
		this.transactionStateDAO = transactionStateDAO;
	}

	public TransactionState getTransactionState(String amount){
		TransactionState res = null;
		long lngAmount = Long.valueOf(amount);
		if (lngAmount <=  Constant.MINIMUM_TRANSFERED_AMOUNT) {
			res = transactionStateDAO.getTransactionStateById(TransactionState.APPROVED_TRANSACTION);
		} else {
			res = transactionStateDAO.getTransactionStateById(TransactionState.PENDING_TRANSACTION);
		}
		
		return res;
	}
}
